/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ModificarModeloIntereses.java
 *
 * Created on 3/10/2012, 11:57:22 PM
 */
package modificaciones;

import Clases.Intereses;
import controlador.Escenario;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author HP G42
 */
public class ModificarModeloIntereses extends javax.swing.JDialog {
    
    private Escenario escenarioNormal;
    private Intereses modificado;

    /** Creates new form ModificarModeloIntereses */
    public ModificarModeloIntereses(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    public void cambiarPrestamo(Escenario escenario, Intereses interes){
        this.setTitle("Modificar préstamo");
        this.escenarioNormal = escenario;
        this.modificado = interes;
        this.cargarDatos();
  
        this.setVisible(true);
    }
    
    public void cargarDatos(){
        if (modificado.getEntidadSupervisada())
            entidadSupervisada.setSelected(true);
        else
            entidadNoSupervisada.setSelected(false);
        
        monto.setText(Double.toString(modificado.getMonto()));
        periodos.setText(Integer.toString(modificado.getPlazoInt()));
        interes.setText(Double.toString(modificado.getTasaInteres()*100));
        capitalizaciones.setText(Integer.toString(modificado.getCapitalizacionesInt()));
        cantidadPagos.setText(Integer.toString(modificado.getNumeroPagosAnualesInt()));
        
        this.rellenarTabla();
        
        if (modificado.getTipoCuota())
            jLabel1.setText("Coutas niveladas");
        else
            jLabel1.setText("Coutas no niveladas");
        
    }

    private void rellenarTabla(){
        double [] cuotas = modificado.getListaCuotasAnuales();
        int [] anios = escenarioNormal.getListaAnios();
        Object [] fila = new Object[modificado.getNumeroPagosAnualesInt()];
        
        DefaultTableModel modelo = new DefaultTableModel();
        for (int i=0; i<cuotas.length; i++){
            modelo.addColumn(anios[i]);
            fila[i]=cuotas[i];
        }
        modelo.addRow(fila);
        jTable1.setModel(modelo);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        nivelada = new javax.swing.JButton();
        noNiveladas = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        entidadSupervisada = new javax.swing.JRadioButton();
        entidadNoSupervisada = new javax.swing.JRadioButton();
        aceptar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        monto = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        periodos = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        interes = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        capitalizaciones = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cantidadPagos = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(flujocaja.FlujoCajaApp.class).getContext().getResourceMap(ModificarModeloIntereses.class);
        nivelada.setText(resourceMap.getString("nivelada.text")); // NOI18N
        nivelada.setName("nivelada"); // NOI18N
        nivelada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                niveladaActionPerformed(evt);
            }
        });

        noNiveladas.setText(resourceMap.getString("noNiveladas.text")); // NOI18N
        noNiveladas.setName("noNiveladas"); // NOI18N
        noNiveladas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noNiveladasActionPerformed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel5.border.title"))); // NOI18N
        jPanel5.setName("jPanel5"); // NOI18N

        buttonGroup1.add(entidadSupervisada);
        entidadSupervisada.setSelected(true);
        entidadSupervisada.setText(resourceMap.getString("entidadSupervisada.text")); // NOI18N
        entidadSupervisada.setName("entidadSupervisada"); // NOI18N

        buttonGroup1.add(entidadNoSupervisada);
        entidadNoSupervisada.setText(resourceMap.getString("entidadNoSupervisada.text")); // NOI18N
        entidadNoSupervisada.setName("entidadNoSupervisada"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(entidadSupervisada)
                    .addComponent(entidadNoSupervisada))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(entidadSupervisada)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(entidadNoSupervisada))
        );

        aceptar.setText(resourceMap.getString("aceptar.text")); // NOI18N
        aceptar.setName("aceptar"); // NOI18N
        aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel1.border.title"))); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
                    .addComponent(jLabel1))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                .addContainerGap())
        );

        monto.setName("monto"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        periodos.setName("periodos"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        interes.setName("interes"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        capitalizaciones.setText(resourceMap.getString("capitalizaciones.text")); // NOI18N
        capitalizaciones.setName("capitalizaciones"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        cantidadPagos.setName("cantidadPagos"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5)
                                .addComponent(jLabel6)
                                .addComponent(jLabel7))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(cantidadPagos, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(capitalizaciones, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(interes, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(monto, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(periodos, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE))))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(nivelada)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(noNiveladas)
                            .addGap(207, 207, 207)))
                    .addComponent(aceptar, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(monto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(periodos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(interes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(capitalizaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cantidadPagos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nivelada)
                    .addComponent(noNiveladas))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addComponent(aceptar))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void niveladaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_niveladaActionPerformed
        // TODO add your handling code here:
        modificado.setMonto(Double.parseDouble(monto.getText()));
        modificado.setPlazoInt(Integer.parseInt(periodos.getText()));
        modificado.setTasaInteres(Double.parseDouble(interes.getText())/100);
        modificado.setCapitalizacionesInt(Integer.parseInt(capitalizaciones.getText()));
        modificado.setNumeroPagosAnualesInt(Integer.parseInt(cantidadPagos.getText()));
        modificado.setEntidadSupervisada(entidadSupervisada.isSelected());
        modificado.setTipoCuota(true);
        jLabel1.setText("Cuotas niveladas");
        modificado.calcularCuotas();
        this.rellenarTabla();
    }//GEN-LAST:event_niveladaActionPerformed

    private void noNiveladasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noNiveladasActionPerformed
        // TODO add your handling code here:
        modificado.setMonto(Double.parseDouble(monto.getText()));
        modificado.setPlazoInt(Integer.parseInt(periodos.getText()));
        modificado.setTasaInteres(Double.parseDouble(interes.getText())/100);
        modificado.setCapitalizacionesInt(Integer.parseInt(capitalizaciones.getText()));
        modificado.setNumeroPagosAnualesInt(Integer.parseInt(cantidadPagos.getText()));
        modificado.setEntidadSupervisada(entidadSupervisada.isSelected());
        modificado.setTipoCuota(false);
        jLabel1.setText("Cuotas no niveladas");
        modificado.calcularCuotas();
        this.rellenarTabla();
    }//GEN-LAST:event_noNiveladasActionPerformed

    private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_aceptarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModificarModeloIntereses.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModificarModeloIntereses.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModificarModeloIntereses.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModificarModeloIntereses.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ModificarModeloIntereses dialog = new ModificarModeloIntereses(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField cantidadPagos;
    private javax.swing.JTextField capitalizaciones;
    private javax.swing.JRadioButton entidadNoSupervisada;
    private javax.swing.JRadioButton entidadSupervisada;
    private javax.swing.JTextField interes;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField monto;
    private javax.swing.JButton nivelada;
    private javax.swing.JButton noNiveladas;
    private javax.swing.JTextField periodos;
    // End of variables declaration//GEN-END:variables
}
